function sucess(selector) {
    return function(msg){
     jq(selector).get(0).innerHTML=msg
   }
}

function error(selector) {
    return function(msg){
     jq(selector).get(0).innerHTML="Erro Carregando Combo!"
   }
}

jq(document).ready(function() {
jq.ajax({
   type: "GET",
   url: "get_structure",
   data: "structure=tables_names",
   success: sucess('#table_name'),
   error: error('#div_table_name'),
 });
}) 

jq("#table_name").change(function() {
jq.ajax({
   type: "GET",
   url: "get_structure",
   data: "structure=columns_datetime&object_id=" + this.value,
   success: sucess('#field_order'),
   error: error('#div_field_order'),
 });
}) 

jq("#table_name").change(function() {
jq.ajax({
   type: "GET",
   url: "get_structure",
   data: "structure=columns_number&object_id=" + this.value,
   success: sucess('#field_valor'),
   error: error('#div_field_valor'),
 });
}) 

jq("#btnCriarGrafico").click(function() {
tn = jq("#table_name").get(0).value
fo = jq("#field_order").get(0).value
fv = jq("#field_valor").get(0).value
pt = jq("#periodo_type").get(0).value
df = jq("#data_from").get(0).value
dt = jq("#data_to").get(0).value
to = jq("#type_order").get(0).value

url_chart = 'index/?tn=' + tn + '&fo=' + fo + '&fv=' + fv + '&pt=' + pt + '&df=' + df + '&dt=' + dt + '&to=' + to;
window.open(url_chart,name='Indice por Periodo','width=800,height=600', false)
});
